package com.sdp.lease.utils;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class DbGeneratorPg {

	/**
	 * 一对一数据模型，生成方法
	 * @param args
	 */
	public static void main(String[] args) {
		AutoGenerator generator = new AutoGenerator();
		GlobalConfig globalConfig = new GlobalConfig();
		globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
		globalConfig.setAuthor("zsp");
		globalConfig.setOpen(false);
		globalConfig.setFileOverride(true);
		globalConfig.setActiveRecord(true);
		generator.setGlobalConfig(globalConfig);

		  // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:postgresql://192.168.3.3:5432/zsp");
        dsc.setDriverName("org.postgresql.Driver");
        dsc.setUsername("zsp");
        dsc.setPassword("zsp@840107");
        dsc.setSchemaName("equipment-lease");
        generator.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.sdp.lease.db.l_sys_config");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setXml("mapper.xml");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setController("web");
        generator.setPackageInfo(pc);


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        //strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setSkipView(true);
        strategy.setEntityTableFieldAnnotationEnable(true);
        //"act_re_model", "act_hi_procinst", "act_re_procdef"
        strategy.setInclude("l_sys_config");
        generator.setStrategy(strategy);

        generator.execute();

		System.out.println(System.getProperty("user.dir"));

	}
}
